home *** CD-ROM | disk | FTP | other *** search
- ##======================================================================
- #
- # Request preprocessing script.
- #
- # This script gets control at the start of each request, after the URL
- # is parsed. We intend to use it to manage state between requests via
- # parameters on the URL (alternatively, we could use cookies, too, but
- # we're not sure how widely they are implemented now).
- #
- # Possible return values are:
- # Proceed (="Everything is swell, go to the next step"),
- # Exit (="We have finished processing this request"),
- # NoAction (="This URL was not meant for us"), and
- # Abort (="Something's wrong, please send an error to client")
- #
- # Notes:
- # Use "exit" if you want to prevent any further processing
- # from occurring. You should have already sent a response
- # back to the client.
- #
- # Use "abort" or "noaction" only if you have not sent anything back
- # to the client. "noaction" is sort of useless and should probably be
- # avoided.
- #
- # IMPORTANT NOTE REGARDING TCL PROCS!
- # If you define any TCL procs, they must be defined from within a
- # the same dwScript where you run the proc, or in any dwScript that
- # was run before you try to call the proc. For sanity, we suggest that
- # you define most of your procs right up front in the preprocess script.
- #
- # We pick up parameters from the URL here. By convention, we use
- # two-letter codes:
- #
- # cd - default collection TOC depth (number)
- # td - default book TOC depth (number)
- # hf - 0="no frames" 1="generate frames"
- # ht - 0="no tables" 1="use tables"
- # he - 0="no entities" 1="use entities"
- #
- ##=======================================================================
-
- dwOnEvent PreProcessRequest HandlePreProcessRequestEvent
- dwOnEvent PostProcessRequest HandlePostProcessRequestEvent
-
- dwScript HandlePreProcessRequestEvent {
-
- ## Load up the proc's!
- ## NOTE: Full path for Windows NT & 95, where relative paths are broken.
- dwSource [dwGetParam CONFIG_DIR]/procdef.dwc
-
- ##========================================================================
- ## Main body starts from here
- ##========================================================================
-
- ## Get our capability list
- set capabilities [dwSenseClientCapabilities]
-
- ##==========================================================================
- ## Get the query form string (looks like ?DwebQueryForm=foo tacked on end
- ## of URL). This is a special form of query that needs to have the
- ## rest of the query parameters substituted into it.
- ##==========================================================================
-
- set query_form [dwGetUrlQueryParam DwebQueryForm]
- if {$query_form != ""} {
- dwDelUrlQueryParam DwebQueryForm
- set ok 1
- while {$ok} {
- set ok [regexp {\$([a-zA-Z0-9]+)} $query_form junk param]
- if {$ok} {
- set sub [dwGetUrlQueryParam $param]
- set ok [regsub {\$([a-zA-Z0-9]+)} $query_form $sub query_form]
- }
- }
- dwSetUrlQueryParams "DwebQuery=[dwUrlEncode $query_form]"
- }
-
- # Do not put comments before switch selectors... it will cause them not
- # to match
- set locale [dwGetParam "dwServerLocale"]
- switch -exact -- $locale {
- "ja" {
- # Japanese locale. Tries to send deal with SJIS with MS Windows
- # machines, and EUC for UNIX boxes.
- #
- # Set the output encoding according to platform
- if {[dwQueryCapability "platform" $capabilities] == "unix"} {
- dwSetOutputEncoding "euc-jp"
- } else {
- dwSetOutputEncoding "shift-jis"
- }
- # Some browsers do not react well to certain values in the
- # charset parameter, so we tailor for that here.
- if {[dwQueryCapability "broken_charset" $capabilities] == "1"} {
- dwSetContentType "text/html"
- } else {
- dwSetContentType \
- "text/html; charset=[dwMapEcmToIANA [dwGetOutputEncoding]]"
- }
- # The following will break with certain clients that don't stick
- # to the conventions of sending back whatever the server sends
- # to you. If clients actually provided proper labelling, there
- # would be no guesswork here....
- dwSet ActiveQuery [dwGetUrlQueryParam DwebQuery]
- if {$ActiveQuery != ""} {
- dwSet QueryEncoding [dwDetectStringEncoding $ActiveQuery "ja"]
- if {[dwQueryCapability "platform" $capabilities] == "unix"} {
- # Give priority to EUC for UNIX boxes
- if {[lsearch $QueryEncoding "*euc-jp*"] != -1} {
- dwSet ActiveQuery \
- [dwConvertEncoding $ActiveQuery "euc-jp"]
- } else {
- if {[lsearch $QueryEncoding "*shift-jis*"] != -1} {
- dwSet ActiveQuery \
- [dwConvertEncoding $ActiveQuery "shift-jis"]
- } else {
- dwSet ActiveQuery \
- [dwConvertEncoding $ActiveQuery "euc-jp"]
- }
- }
- } else {
- # Give priority to SJIS for WINDOWS boxes
- if {[lsearch $QueryEncoding "*shift-jis*"] != -1} {
- dwSet ActiveQuery \
- [dwConvertEncoding $ActiveQuery "shift-jis"]
- } else {
- if {[lsearch $QueryEncoding "*euc-jp*"] != -1} {
- dwSet ActiveQuery \
- [dwConvertEncoding $ActiveQuery "euc-jp"]
- } else {
- dwSet ActiveQuery \
- [dwConvertEncoding $ActiveQuery "shift-jis"]
- }
- }
- }
- dwSetQuery "$ActiveQuery"
- }
- }
- "default" {
- # Locale for English or close relatives. This is the default
- dwSetOutputEncoding "C"
- dwSetContentType \
- "text/html; charset=[dwMapEcmToIANA [dwGetOutputEncoding]]"
- dwSet ActiveQuery [dwGetUrlQueryParam DwebQuery]
- if {$ActiveQuery != ""} {
- dwSet ActiveQuery [dwConvertEncoding $ActiveQuery "C"]
- dwSetQuery "$ActiveQuery"
- }
- }
- }
-
- ## chunking amount
- dwSetPageMaxBytesHint 60000
-
- ## Get the state params
- dwSet State__FramesSupport [dwQueryCapability "frames" $capabilities]
- dwSet State__Frames [dwGetUrlParam hf $State__FramesSupport]
- dwSet State__Tables [dwGetUrlParam ht [dwQueryCapability "tables" $capabilities]]
- dwSet State__Entities [dwGetUrlParam he [dwQueryCapability "entities" $capabilities]]
- dwSet State__TocDepth [dwGetUrlParam td [dwGetParam Default__TocDepth]]
- dwSet State__CollTocDepth [dwGetUrlParam cd [dwGetParam Default__CollTocDepth]]
-
- ## Note that ContentStylesheet and TocStylesheet default to "default"
- ## but are set in Collects.dwc and can be changed by the user to other
- ## filenames
- dwSet State__ContentStyle [dwGetUrlParam cs [dwGetParam ContentStylesheet]]
- dwSet State__TocStyle [dwGetUrlParam ts [dwGetParam TocStylesheet]]
-
- ## These are request-specific state variables (probably should not
- ## become cookies when we convert).
- dwSet State__TocLoc [dwGetUrlParam tl ""]
- dwSet State__UpdateOtherFrames [dwGetUrlParam uf 1]
- dwSet State__NoNavigation [dwGetUrlParam nn 0]
- dwSet State__NoAutoHit [dwGetUrlParam nh 0]
-
-
- ##==========================================================================
- ## Some random flags that need initializing per request.
- ##==========================================================================
-
- dwSet DoReveal 0
- dwSet TextStylesheet $State__ContentStyle
- dwSet ShowingRootCollection 0
-
- dwCall dwMakeUrlParts
-
- if {[dwGet Service] == "infosrch"} {
- dwSet State__UpdateOtherFrames 0
- }
-
- return Proceed
- }
-
- dwScript HandlePostProcessRequestEvent {
- ## Nothing defined here!
- }
-
-
- ##======================================================================
- ## Default "Collection View" script.
- ## Called by the plug-in (C code) if there's no script in the URL
- ##======================================================================
- dwScript DefaultCollectionView {
- dwCall Generic__CollectionView
- }
-
-
- ##======================================================================
- ## Default "Book View" script.
- ## Called by the plug-in (C code) if here's no script in the URL
- ##======================================================================
- dwScript DefaultBookView {
- dwCall Generic__BookView
- }
-
-
-